package com.geekaca.testthread.testtimer;

import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class TimerDemo1 {
    public static void main(String[] args) {
        /**
         * Timer 方式 定时器
         */
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName()+" 执行AAA" + new Date());
            }
        },0,1000);

        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                try {
                    System.out.println(Thread.currentThread().getName()+" 执行BBB" + new Date());
//                    System.out.println(10/0);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        },0,3000);

        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName()+" 执行CCC" + new Date());
            }
        },0,3000);

    }
}
